<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>极光跑酷者 - Emoji版</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Press+Start+2P&display=swap');
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Orbitron', sans-serif;
            background: #0a0a1a;
            color: #e0e0ff;
            overflow: hidden;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        #game-container {
            position: relative;
            width: 800px;
            height: 500px;
            background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
            border-radius: 15px;
            box-shadow: 0 0 30px rgba(100, 100, 255, 0.3);
            overflow: hidden;
        }
        
        #start-screen, #game-over-screen {
            position: absolute;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background: rgba(10, 10, 30, 0.9);
            z-index: 10;
            backdrop-filter: blur(5px);
        }
        
        #game-over-screen {
            display: none;
        }
        
        h1 {
            font-family: 'Press Start 2P', cursive;
            font-size: 3rem;
            margin-bottom: 30px;
            background: linear-gradient(90deg, #00d2ff, #3a7bd5);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            text-shadow: 0 0 10px rgba(58, 123, 213, 0.5);
        }
        
        .btn {
            padding: 12px 30px;
            margin: 10px;
            font-family: 'Orbitron', sans-serif;
            font-weight: bold;
            background: linear-gradient(90deg, #3a7bd5, #00d2ff);
            border: none;
            border-radius: 50px;
            color: white;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 5px 15px rgba(58, 123, 213, 0.4);
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(58, 123, 213, 0.6);
        }
        
        .btn:active {
            transform: translateY(1px);
        }
        
        #game-screen {
            width: 100%;
            height: 100%;
            position: relative;
            display: none;
        }
        
        #player {
            position: absolute;
            width: 80px;
            height: 80px;
            bottom: 100px;
            left: 100px;
            z-index: 5;
            transition: transform 0.1s;
            font-size: 60px;
            text-align: center;
            line-height: 80px;
            filter: drop-shadow(0 0 5px rgba(0, 210, 255, 0.7));
        }
        
        .obstacle {
            position: absolute;
            width: 50px;
            height: 50px;
            bottom: 100px;
            background: linear-gradient(135deg, #ff416c, #ff4b2b);
            border-radius: 10px;
            box-shadow: 0 0 15px rgba(255, 65, 108, 0.7);
            z-index: 4;
        }
        
        .coin {
            position: absolute;
            width: 30px;
            height: 30px;
            background: radial-gradient(circle at center, #ffd700, #ffaa00);
            border-radius: 50%;
            box-shadow: 0 0 15px rgba(255, 215, 0, 0.7);
            z-index: 3;
            animation: pulse 1s infinite alternate;
        }
        
        @keyframes pulse {
            from { transform: scale(1); }
            to { transform: scale(1.2); }
        }
        
        #score-display {
            position: absolute;
            top: 20px;
            right: 20px;
            font-size: 1.5rem;
            color: white;
            text-shadow: 0 0 5px rgba(255, 255, 255, 0.7);
            z-index: 6;
        }
        
        #high-score-display {
            position: absolute;
            top: 50px;
            right: 20px;
            font-size: 1rem;
            color: #00d2ff;
            z-index: 6;
        }
        
        #skill-meter {
            position: absolute;
            bottom: 20px;
            left: 20px;
            width: 200px;
            height: 20px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            overflow: hidden;
            z-index: 6;
        }
        
        #skill-fill {
            height: 100%;
            width: 0%;
            background: linear-gradient(90deg, #00d2ff, #3a7bd5);
            border-radius: 10px;
            transition: width 0.3s;
        }
        
        #skill-btn {
            position: absolute;
            bottom: 20px;
            left: 240px;
            padding: 5px 15px;
            background: linear-gradient(90deg, #ff416c, #ff4b2b);
            border: none;
            border-radius: 50px;
            color: white;
            cursor: pointer;
            font-family: 'Orbitron', sans-serif;
            font-weight: bold;
            box-shadow: 0 0 10px rgba(255, 65, 108, 0.5);
            opacity: 0.5;
            pointer-events: none;
        }
        
        #skill-btn.active {
            opacity: 1;
            pointer-events: all;
        }
        
        .star {
            position: absolute;
            width: 2px;
            height: 2px;
            background: white;
            border-radius: 50%;
            animation: twinkle 2s infinite alternate;
        }
        
        @keyframes twinkle {
            from { opacity: 0.2; }
            to { opacity: 1; }
        }
        
        .aurora {
            position: absolute;
            width: 100%;
            height: 100%;
            background: linear-gradient(0deg, rgba(0,210,255,0.1) 0%, rgba(58,123,213,0.1) 100%);
            opacity: 0.5;
            z-index: 1;
            animation: auroraFlow 15s infinite alternate;
        }
        
        @keyframes auroraFlow {
            0% { transform: translateY(0) scale(1); opacity: 0.3; }
            50% { transform: translateY(-50px) scale(1.1); opacity: 0.7; }
            100% { transform: translateY(0) scale(1); opacity: 0.3; }
        }
        
        #history-modal {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 400px;
            background: rgba(20, 20, 50, 0.95);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 0 30px rgba(100, 100, 255, 0.5);
            z-index: 20;
            display: none;
            backdrop-filter: blur(10px);
        }
        
        #history-modal h2 {
            margin-bottom: 20px;
            color: #00d2ff;
            text-align: center;
        }
        
        #history-list {
            list-style-type: none;
            max-height: 300px;
            overflow-y: auto;
        }
        
        #history-list li {
            padding: 10px;
            margin: 5px 0;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 5px;
            display: flex;
            justify-content: space-between;
        }
        
        #close-history {
            position: absolute;
            top: 10px;
            right: 10px;
            background: none;
            border: none;
            color: #ff416c;
            font-size: 1.5rem;
            cursor: pointer;
        }
        
        .power-up {
            position: absolute;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            z-index: 3;
            animation: float 3s infinite ease-in-out;
            font-size: 30px;
            text-align: center;
            line-height: 40px;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-20px); }
        }
        
        .shield {
            background: radial-gradient(circle at center, rgba(0, 210, 255, 0.8), rgba(58, 123, 213, 0.8));
            box-shadow: 0 0 20px rgba(0, 210, 255, 0.7);
        }
        
        .speed {
            background: radial-gradient(circle at center, rgba(255, 215, 0, 0.8), rgba(255, 170, 0, 0.8));
            box-shadow: 0 0 20px rgba(255, 215, 0, 0.7);
        }
        
        .player-shield {
            position: absolute;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background: radial-gradient(circle at center, rgba(0, 210, 255, 0.3), transparent 70%);
            border: 2px solid rgba(0, 210, 255, 0.5);
            top: -10px;
            left: -10px;
            z-index: 4;
            display: none;
        }
        
        .player-speed {
            filter: hue-rotate(90deg);
            animation: speedEffect 0.2s infinite alternate;
        }
        
        @keyframes speedEffect {
            from { filter: hue-rotate(90deg) brightness(1.2); }
            to { filter: hue-rotate(90deg) brightness(1.5); }
        }

        /* 角色动画 */
        @keyframes bounce {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }

        .running {
            animation: bounce 0.6s infinite;
        }
    </style>
</head>
<body>
    <div id="game-container">
        <!-- 开始界面 -->
        <div id="start-screen">
            <h1>极光跑酷者</h1>
            <p>穿越星空，收集能量，躲避障碍</p>
            <button id="start-btn" class="btn">开始游戏</button>
            <button id="history-btn" class="btn">历史分数</button>
        </div>
        
        <!-- 游戏结束界面 -->
        <div id="game-over-screen">
            <h1>游戏结束</h1>
            <p id="final-score">得分: 0</p>
            <p id="new-high-score" style="color: #ffd700; display: none;">新纪录!</p>
            <button id="restart-btn" class="btn">再来一次</button>
            <button id="back-to-menu" class="btn">返回菜单</button>
        </div>
        
        <!-- 游戏主界面 -->
        <div id="game-screen">
            <!-- 极光背景效果 -->
            <div class="aurora"></div>
            
            <!-- 星空背景 -->
            <div id="stars-container"></div>
            
            <!-- 玩家角色 - 使用Emoji -->
            <div id="player">🏄‍♂️</div>
            
            <!-- 障碍物和金币会通过JS动态生成 -->
            
            <!-- 游戏UI -->
            <div id="score-display">得分: 0</div>
            <div id="high-score-display">最高分: 0</div>
            
            <!-- 技能系统 -->
            <div id="skill-meter">
                <div id="skill-fill"></div>
            </div>
            <button id="skill-btn" disabled>冲刺!</button>
        </div>
        
        <!-- 历史分数弹窗 -->
        <div id="history-modal">
            <button id="close-history">&times;</button>
            <h2>历史分数</h2>
            <ul id="history-list">
                <!-- 分数会通过JS动态添加 -->
            </ul>
        </div>
    </div>

    <script>
        // 游戏变量
        let gameRunning = false;
        let score = 0;
        let highScore = localStorage.getItem('highScore') || 0;
        let gameSpeed = 5;
        let obstacleInterval;
        let coinInterval;
        let powerUpInterval;
        let isJumping = false;
        let isInvincible = false;
        let isSpeedBoost = false;
        let skillMeter = 0;
        let gameHistory = JSON.parse(localStorage.getItem('gameHistory')) || [];
        
        // DOM元素
        const startScreen = document.getElementById('start-screen');
        const gameOverScreen = document.getElementById('game-over-screen');
        const gameScreen = document.getElementById('game-screen');
        const startBtn = document.getElementById('start-btn');
        const historyBtn = document.getElementById('history-btn');
        const restartBtn = document.getElementById('restart-btn');
        const backToMenu = document.getElementById('back-to-menu');
        const player = document.getElementById('player');
        const scoreDisplay = document.getElementById('score-display');
        const highScoreDisplay = document.getElementById('high-score-display');
        const finalScoreDisplay = document.getElementById('final-score');
        const newHighScoreDisplay = document.getElementById('new-high-score');
        const skillMeterFill = document.getElementById('skill-fill');
        const skillBtn = document.getElementById('skill-btn');
        const historyModal = document.getElementById('history-modal');
        const closeHistory = document.getElementById('close-history');
        const historyList = document.getElementById('history-list');
        const starsContainer = document.getElementById('stars-container');
        const playerShield = document.createElement('div');
        playerShield.className = 'player-shield';
        player.appendChild(playerShield);
        
        // 创建星空背景
        function createStars() {
            starsContainer.innerHTML = '';
            for (let i = 0; i < 100; i++) {
                const star = document.createElement('div');
                star.className = 'star';
                star.style.left = `${Math.random() * 100}%`;
                star.style.top = `${Math.random() * 100}%`;
                star.style.width = `${Math.random() * 3 + 1}px`;
                star.style.height = star.style.width;
                star.style.animationDelay = `${Math.random() * 2}s`;
                starsContainer.appendChild(star);
            }
        }
        
        // 初始化游戏
        function initGame() {
            createStars();
            highScoreDisplay.textContent = `最高分: ${highScore}`;
            
            // 清除所有障碍物和金币
            document.querySelectorAll('.obstacle, .coin, .power-up').forEach(el => el.remove());
            
            // 重置玩家位置和状态
            player.style.bottom = '100px';
            player.style.left = '100px';
            player.classList.add('running');
            playerShield.style.display = 'none';
            
            // 重置游戏状态
            score = 0;
            gameSpeed = 5;
            isJumping = false;
            isInvincible = false;
            isSpeedBoost = false;
            skillMeter = 0;
            updateSkillMeter();
            
            scoreDisplay.textContent = `得分: ${score}`;
        }
        
        // 开始游戏
        function startGame() {
            initGame();
            startScreen.style.display = 'none';
            gameOverScreen.style.display = 'none';
            gameScreen.style.display = 'block';
            gameRunning = true;
            
            // 生成障碍物
            obstacleInterval = setInterval(createObstacle, 2000);
            
            // 生成金币
            coinInterval = setInterval(createCoin, 1500);
            
            // 生成能量道具
            powerUpInterval = setInterval(createPowerUp, 10000);
            
            // 游戏主循环
            requestAnimationFrame(gameLoop);
        }
        
        // 游戏主循环
        function gameLoop() {
            if (!gameRunning) return;
            
            // 移动障碍物和金币
            moveElements();
            
            // 检测碰撞
            checkCollisions();
            
            // 增加分数
            score += 1;
            scoreDisplay.textContent = `得分: ${score}`;
            
            // 每1000分增加游戏速度
            if (score % 1000 === 0) {
                gameSpeed += 0.5;
            }
            
            // 每500分增加技能条
            if (score % 500 === 0) {
                skillMeter += 10;
                if (skillMeter > 100) skillMeter = 100;
                updateSkillMeter();
            }
            
            requestAnimationFrame(gameLoop);
        }
        
        // 创建障碍物
        function createObstacle() {
            if (!gameRunning) return;
            
            const obstacle = document.createElement('div');
            obstacle.className = 'obstacle';
            obstacle.style.left = '800px';
            obstacle.style.bottom = '100px';
            
            // 随机高度
            const height = Math.random() * 50 + 30;
            obstacle.style.height = `${height}px`;
            obstacle.style.bottom = `calc(100px - ${height - 50}px)`;
            
            // 随机颜色
            const hue = Math.random() * 60 + 350; // 红色到紫色范围
            obstacle.style.background = `linear-gradient(135deg, hsl(${hue}, 100%, 70%), hsl(${hue + 20}, 100%, 50%)`;
            
            gameScreen.appendChild(obstacle);
        }
        
        // 创建金币
        function createCoin() {
            if (!gameRunning) return;
            
            const coin = document.createElement('div');
            coin.className = 'coin';
            coin.style.left = '800px';
            coin.style.bottom = `${Math.random() * 200 + 150}px`;
            gameScreen.appendChild(coin);
        }
        
        // 创建能量道具
        function createPowerUp() {
            if (!gameRunning) return;
            
            const powerUp = document.createElement('div');
            const type = Math.random() > 0.5 ? 'shield' : 'speed';
            powerUp.className = `power-up ${type}`;
            powerUp.style.left = '800px';
            powerUp.style.bottom = `${Math.random() * 200 + 150}px`;
            
            // 使用Emoji作为道具图标
            if (type === 'shield') {
                powerUp.textContent = '🛡️';
            } else {
                powerUp.textContent = '⚡';
            }
            
            gameScreen.appendChild(powerUp);
        }
        
        // 移动所有元素
        function moveElements() {
            // 移动障碍物
            document.querySelectorAll('.obstacle').forEach(obstacle => {
                const currentLeft = parseInt(obstacle.style.left);
                const newLeft = currentLeft - gameSpeed * (isSpeedBoost ? 1.5 : 1);
                obstacle.style.left = `${newLeft}px`;
                
                // 移除屏幕外的障碍物
                if (newLeft < -50) {
                    obstacle.remove();
                }
            });
            
            // 移动金币
            document.querySelectorAll('.coin').forEach(coin => {
                const currentLeft = parseInt(coin.style.left);
                const newLeft = currentLeft - gameSpeed * (isSpeedBoost ? 1.5 : 1);
                coin.style.left = `${newLeft}px`;
                
                // 移除屏幕外的金币
                if (newLeft < -30) {
                    coin.remove();
                }
            });
            
            // 移动能量道具
            document.querySelectorAll('.power-up').forEach(powerUp => {
                const currentLeft = parseInt(powerUp.style.left);
                const newLeft = currentLeft - gameSpeed * (isSpeedBoost ? 1.5 : 1);
                powerUp.style.left = `${newLeft}px`;
                
                // 移除屏幕外的能量道具
                if (newLeft < -40) {
                    powerUp.remove();
                }
            });
        }
        
        // 检测碰撞
        function checkCollisions() {
            if (isInvincible) return;
            
            const playerRect = player.getBoundingClientRect();
            
            // 检测障碍物碰撞
            document.querySelectorAll('.obstacle').forEach(obstacle => {
                const obstacleRect = obstacle.getBoundingClientRect();
                
                if (
                    playerRect.right > obstacleRect.left &&
                    playerRect.left < obstacleRect.right &&
                    playerRect.bottom > obstacleRect.top &&
                    playerRect.top < obstacleRect.bottom
                ) {
                    gameOver();
                }
            });
            
            // 检测金币碰撞
            document.querySelectorAll('.coin').forEach(coin => {
                const coinRect = coin.getBoundingClientRect();
                
                if (
                    playerRect.right > coinRect.left &&
                    playerRect.left < coinRect.right &&
                    playerRect.bottom > coinRect.top &&
                    playerRect.top < coinRect.bottom
                ) {
                    // 增加分数
                    score += 100;
                    scoreDisplay.textContent = `得分: ${score}`;
                    
                    // 增加技能条
                    skillMeter += 5;
                    if (skillMeter > 100) skillMeter = 100;
                    updateSkillMeter();
                    
                    // 移除金币
                    coin.remove();
                }
            });
            
            // 检测能量道具碰撞
            document.querySelectorAll('.power-up').forEach(powerUp => {
                const powerUpRect = powerUp.getBoundingClientRect();
                
                if (
                    playerRect.right > powerUpRect.left &&
                    playerRect.left < powerUpRect.right &&
                    playerRect.bottom > powerUpRect.top &&
                    playerRect.top < powerUpRect.bottom
                ) {
                    if (powerUp.classList.contains('shield')) {
                        activateShield();
                    } else if (powerUp.classList.contains('speed')) {
                        activateSpeedBoost();
                    }
                    
                    // 移除能量道具
                    powerUp.remove();
                }
            });
        }
        
        // 激活护盾
        function activateShield() {
            isInvincible = true;
            playerShield.style.display = 'block';
            player.textContent = '🦸'; // 改变角色为超级英雄emoji
            
            // 5秒后护盾消失
            setTimeout(() => {
                isInvincible = false;
                playerShield.style.display = 'none';
                player.textContent = '🏄‍'; // 恢复为跑步emoji
            }, 5000);
        }
        
        // 激活加速
        function activateSpeedBoost() {
            isSpeedBoost = true;
            player.classList.add('player-speed');
            player.textContent = '🚀'; // 改变角色为火箭emoji
            
            // 3秒后加速消失
            setTimeout(() => {
                isSpeedBoost = false;
                player.classList.remove('player-speed');
                player.textContent = '🏄‍'; // 恢复为跑步emoji
            }, 3000);
        }
        
        // 更新技能条
        function updateSkillMeter() {
            skillMeterFill.style.width = `${skillMeter}%`;
            
            if (skillMeter >= 100) {
                skillBtn.classList.add('active');
                skillBtn.disabled = false;
            } else {
                skillBtn.classList.remove('active');
                skillBtn.disabled = true;
            }
        }
        
        // 使用技能
        function useSkill() {
            if (skillMeter < 100) return;
            
            skillMeter = 0;
            updateSkillMeter();
            
            // 冲刺效果
            const originalSpeed = gameSpeed;
            gameSpeed *= 2;
            player.textContent = '💨'; // 改变角色为冲刺emoji
            
            // 2秒后恢复正常速度
            setTimeout(() => {
                gameSpeed = originalSpeed;
                player.textContent = '🏄‍'; // 恢复为跑步emoji
            }, 2000);
        }
        
        // 游戏结束
        function gameOver() {
            gameRunning = false;
            clearInterval(obstacleInterval);
            clearInterval(coinInterval);
            clearInterval(powerUpInterval);
            
            // 更新最高分
            if (score > highScore) {
                highScore = score;
                localStorage.setItem('highScore', highScore);
                newHighScoreDisplay.style.display = 'block';
            } else {
                newHighScoreDisplay.style.display = 'none';
            }
            
            // 保存游戏记录
            const now = new Date();
            const gameRecord = {
                score: score,
                date: now.toLocaleDateString(),
                time: now.toLocaleTimeString()
            };
            
            gameHistory.unshift(gameRecord);
            if (gameHistory.length > 10) {
                gameHistory = gameHistory.slice(0, 10);
            }
            
            localStorage.setItem('gameHistory', JSON.stringify(gameHistory));
            
            // 显示游戏结束界面
            finalScoreDisplay.textContent = `得分: ${score}`;
            gameOverScreen.style.display = 'flex';
        }
        
        // 显示历史分数
        function showHistory() {
            historyList.innerHTML = '';
            
            if (gameHistory.length === 0) {
                const li = document.createElement('li');
                li.textContent = '暂无游戏记录';
                historyList.appendChild(li);
            } else {
                gameHistory.forEach((record, index) => {
                    const li = document.createElement('li');
                    li.innerHTML = `
                        <span>${index + 1}. ${record.date} ${record.time}</span>
                        <span>${record.score}</span>
                    `;
                    historyList.appendChild(li);
                });
            }
            
            historyModal.style.display = 'block';
        }
        
        // 事件监听
        startBtn.addEventListener('click', startGame);
        restartBtn.addEventListener('click', startGame);
        backToMenu.addEventListener('click', () => {
            gameOverScreen.style.display = 'none';
            startScreen.style.display = 'flex';
        });
        historyBtn.addEventListener('click', showHistory);
        closeHistory.addEventListener('click', () => {
            historyModal.style.display = 'none';
        });
        skillBtn.addEventListener('click', useSkill);
        
        // 键盘控制
        document.addEventListener('keydown', (e) => {
            if (!gameRunning) return;
            
            // 空格键或上箭头键跳跃
            if ((e.code === 'Space' || e.code === 'ArrowUp') && !isJumping) {
                jump();
            }
            
            // S键使用技能
            if (e.code === 'KeyS') {
                useSkill();
            }
        });
        
        // 点击游戏容器也可以跳跃（移动设备）
        gameScreen.addEventListener('click', () => {
            if (!gameRunning || isJumping) return;
            jump();
        });
        
        // 跳跃函数
        function jump() {
            isJumping = true;
            player.textContent = '🏄‍'; // 
            
            // 跳跃动画
            let jumpHeight = 0;
            const jumpUp = setInterval(() => {
                jumpHeight += 5;
                player.style.bottom = `${100 + jumpHeight}px`;
                
                if (jumpHeight >= 150) {
                    clearInterval(jumpUp);
                    
                    const jumpDown = setInterval(() => {
                        jumpHeight -= 5;
                        player.style.bottom = `${100 + jumpHeight}px`;
                        
                        if (jumpHeight <= 0) {
                            clearInterval(jumpDown);
                            isJumping = false;
                            player.textContent = '🏄‍'; // 恢复为跑步emoji
                        }
                    }, 20);
                }
            }, 20);
        }
        
        // 初始化
        initGame();
    </script>
</body>
</html>